package com.sop.dao.impl;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.sop.dao.PeopleDao;
import com.sop.model.PeopleInfo;
import com.sop.model.vo.PeopleInfoVo;

import common.base.dao.IBaseDaoImpl;
import common.tools.StringTool;

@Repository("peopleDao")
public class PeopleDaoImpl extends IBaseDaoImpl<PeopleInfo,PeopleInfoVo> implements PeopleDao{

//	 @Override  
//	    public List<PeopleInfo> queryForPageInfo(PeopleInfoVo peopleInfoVo) {  
//	        Session session = sessionFactory.getCurrentSession();  
//	        Criteria c = getSearchCriteria(session, peopleInfoVo);  
//	        c=PagingSort(c, peopleInfoVo);//分页与排序
//	        return (List<PeopleInfo>)c.list();  
//	    }  
//	  
//	    @Override  
//	    public int count(PeopleInfoVo peopleInfoVo) {  
//	        Session session = sessionFactory.getCurrentSession();  
//	        Criteria c = getSearchCriteria(session, peopleInfoVo);  
//	          
//	        c.setProjection(Projections.rowCount());  
//	  
//	        return ((Long)c.list().get(0)).intValue();  
//	    }  
	      
	    @Override
	    public Criteria getSearchCriteria(Session session, PeopleInfoVo peopleInfoVo) {  
	        Criteria c = session.createCriteria(PeopleInfo.class);  
	         
	        if(peopleInfoVo.getPeopleInfo()!=null){
	        //检索条件  
	            String name =  peopleInfoVo.getPeopleInfo().getName();  
	            if (StringTool.isStringAvaliable(name)) {  
	                c.add(Restrictions.ilike("name", "%" + name + "%"));  
	            }  
	        }   
	        return c;  
	    }  
	
}
